// index.js
import api from '../../config/setting.js'
Page({
  data: {
    bannerList: [{ 'img': '/images/banner/banner3.png' }],
    notice: '美好家园需要大家的共同参与，请自觉爱护社区里的公共环境。'
  },
  onLoad() {
    let user = wx.getStorageSync('userInfo')
    console.log("token=" + user.token)
    if (!user) {
      console.log('用户为空，未登录');
      // 可以跳转到登录页面
      wx.navigateTo({
        url: '/pages/login/login'
      });
    }
    this.initBannerNotice()
  },
  initBannerNotice() {
    wx.request({
      url: api.banner,
      method: 'GET',
      success: (res) => {
        console.log(res)
        if (res.data.code == 1) {
          this.setData({
            bannerList: res.data.banner,
            notice: res.data.notice.title
          })
        }
      },
      fail: (err) => {
        console.log(err)
      }
    })
  },
  gotoCollection() {
    wx.navigateTo({
      url: '/pages/collection/collection',
    })
  },
  gotoActivity() {
    //切换 tab
    wx.switchTab({
      url: '/pages/activity/activity',
    })
  },
  gotoFace() {
    wx.navigateTo({
      url: '/pages/face/face',
    })
  },
  gotoVoice() {
    wx.navigateTo({
      url: '/pages/voice/voice',
    })
  },
  gotoHeart() {
    wx.navigateTo({
      url: '/pages/heart/heart',
    })
  },
  gotoGoods() {
    wx.navigateTo({
      url: '/pages/goods/goods',
    })
  }
});
